<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Git学习笔记 | jzhmcoo1</title><meta name="keywords" content="Git"><meta name="author" content="lixing"><meta name="copyright" content="lixing"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="本文根据廖雪峰老师的 Git 教程总结的学习笔记">
<meta property="og:type" content="article">
<meta property="og:title" content="Git学习笔记">
<meta property="og:url" content="https://www.lihangzhu.com/2020/07/18/LearnGit/index.html">
<meta property="og:site_name" content="jzhmcoo1">
<meta property="og:description" content="本文根据廖雪峰老师的 Git 教程总结的学习笔记">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/jzhmcoo1/jzhmcoo1picrepo/raw/master/img/git.png">
<meta property="article:published_time" content="2020-07-18T07:36:38.000Z">
<meta property="article:modified_time" content="2020-09-22T03:54:16.579Z">
<meta property="article:author" content="lixing">
<meta property="article:tag" content="Git">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/jzhmcoo1/jzhmcoo1picrepo/raw/master/img/git.png"><link rel="shortcut icon" href="/images/favicon.png"><link rel="canonical" href="https://www.lihangzhu.com/2020/07/18/LearnGit/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta name="google-site-verification" content="pcqGakY4hww-Mg9iGN4mQw6v_y_IRvYmM1l50SAcPpg"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isanchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2020-09-22 11:54:16'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
          const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
          const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
          const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified

          if (t === undefined) {
            if (isLightMode) activateLightMode()
            else if (isDarkMode) activateDarkMode()
            else if (isNotSpecified || hasNoSupport) {
              const now = new Date()
              const hour = now.getHours()
              const isNight = hour <= 6 || hour >= 18
              isNight ? activateDarkMode() : activateLightMode()
            }
            window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
              if (saveToLocal.get('theme') === undefined) {
                e.matches ? activateDarkMode() : activateLightMode()
              }
            })
          } else if (t === 'light') activateLightMode()
          else activateDarkMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const fontSizeVal = saveToLocal.get('global-font-size')
    if (fontSizeVal !== undefined) {
      document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
    }
    })(window)</script><meta name="generator" content="Hexo 5.4.0"><link rel="alternate" href="/atom.xml" title="jzhmcoo1" type="application/atom+xml">
</head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" data-lazy-src="https://jzhmcoo1-1258918430.cos.ap-shanghai.myqcloud.com/markdown/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">36</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">37</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-heartbeat"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/message/"><i class="fa-fw fa fa-coffee"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-user-friends"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://gitee.com/jzhmcoo1/jzhmcoo1picrepo/raw/master/img/git.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">jzhmcoo1</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-heartbeat"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/message/"><i class="fa-fw fa fa-coffee"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-user-friends"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Git学习笔记</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-07-18T07:36:38.000Z" title="发表于 2020-07-18 15:36:38">2020-07-18</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2020-09-22T03:54:16.579Z" title="更新于 2020-09-22 11:54:16">2020-09-22</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/StudyNotes/">StudyNotes</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">3.7k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>16分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>本文根据廖雪峰老师的<code>Git教程</code>进行总结，只是本人为了假设印象手敲了一遍的简略版，原文链接<a target="_blank" rel="noopener" href="https://www.liaoxuefeng.com/wiki/896043488029600">Git教程 - 廖雪峰的官方网站</a></p>
<h1 id="创建版本库"><a href="#创建版本库" class="headerlink" title="创建版本库"></a>创建版本库</h1><h2 id="创建空文件夹"><a href="#创建空文件夹" class="headerlink" title="创建空文件夹"></a>创建空文件夹</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">mkdir LearnGit</span><br><span class="line"><span class="built_in">cd</span> LearnGit</span><br><span class="line"><span class="built_in">pwd</span></span><br><span class="line">/User/lixing/LearnGit</span><br></pre></td></tr></table></figure>

<h2 id="使用git-init命令初始化git仓库"><a href="#使用git-init命令初始化git仓库" class="headerlink" title="使用git init命令初始化git仓库"></a>使用<code>git init</code>命令初始化<code>git</code>仓库</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git init</span><br><span class="line">Initialized empty Git repository <span class="keyword">in</span> /Users/lixing/LearnGit/.git/</span><br></pre></td></tr></table></figure>

<h2 id="使用la命令查看目录"><a href="#使用la命令查看目录" class="headerlink" title="使用la命令查看目录"></a>使用<code>la</code>命令查看目录</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">la</span><br><span class="line">total 0</span><br><span class="line">drwxr-xr-x  9 lixing  staff   288B  7 15 14:43 .git</span><br></pre></td></tr></table></figure>

<h2 id="在根目录下创建新文件readme-md"><a href="#在根目录下创建新文件readme-md" class="headerlink" title="在根目录下创建新文件readme.md"></a>在根目录下创建新文件<code>readme.md</code></h2><figure class="highlight md"><table><tr><td class="code"><pre><span class="line">Git is a version control system.</span><br><span class="line">Git is free software.</span><br></pre></td></tr></table></figure>

<h2 id="使用git-add-lt-文件名-gt-将文件添加到暂存区"><a href="#使用git-add-lt-文件名-gt-将文件添加到暂存区" class="headerlink" title="使用git add &lt;文件名&gt;将文件添加到暂存区"></a>使用<code>git add &lt;文件名&gt;</code>将文件添加到暂存区</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git add readme.md</span><br></pre></td></tr></table></figure>

<h2 id="使用git-commit将文件提交到本地仓库"><a href="#使用git-commit将文件提交到本地仓库" class="headerlink" title="使用git commit将文件提交到本地仓库"></a>使用<code>git commit</code>将文件提交到本地仓库</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git commit -m <span class="string">&quot;wrote a readme file.&quot;</span></span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">[master (root-commit) c81e9cb] wrote a readme file.</span><br><span class="line"> 1 file changed, 2 insertions(+)</span><br><span class="line"> create mode 100644 readme.md</span><br></pre></td></tr></table></figure>

<h1 id="历史记录管理"><a href="#历史记录管理" class="headerlink" title="历史记录管理"></a>历史记录管理</h1><h2 id="使用git-status查看仓库当前状态"><a href="#使用git-status查看仓库当前状态" class="headerlink" title="使用git status查看仓库当前状态"></a>使用<code>git status</code>查看仓库当前状态</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git status</span><br><span class="line">On branch master</span><br><span class="line">nothing to commit, working tree clean</span><br></pre></td></tr></table></figure>

<p>我们修改<code>readme.md</code></p>
<figure class="highlight md"><table><tr><td class="code"><pre><span class="line">Git is a distributed version control system.</span><br><span class="line">Git is free software.</span><br></pre></td></tr></table></figure>

<p>使用<code>git status</code>命令查看结果</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git status</span><br><span class="line"></span><br><span class="line">On branch master</span><br><span class="line">Changes not staged <span class="keyword">for</span> commit:</span><br><span class="line">  (use <span class="string">&quot;git add &lt;file&gt;...&quot;</span> to update what will be committed)</span><br><span class="line">  (use <span class="string">&quot;git restore &lt;file&gt;...&quot;</span> to discard changes <span class="keyword">in</span> working directory)</span><br><span class="line">    modified:   readme.md</span><br><span class="line"></span><br><span class="line">no changes added to commit (use <span class="string">&quot;git add&quot;</span> and/or <span class="string">&quot;git commit -a&quot;</span>)</span><br></pre></td></tr></table></figure>

<p>可以看到它提示<code>readme.md</code>还未被提交修改</p>
<h2 id="使用git-diff-lt-文件名-gt-查看具体修改内容"><a href="#使用git-diff-lt-文件名-gt-查看具体修改内容" class="headerlink" title="使用git diff &lt;文件名&gt;查看具体修改内容"></a>使用<code>git diff &lt;文件名&gt;</code>查看具体修改内容</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git diff readme.md</span><br><span class="line"></span><br><span class="line">diff --git a/readme.md b/readme.md</span><br><span class="line">index 46d49bf..013b5bc 100644</span><br><span class="line">--- a/readme.md</span><br><span class="line">+++ b/readme.md</span><br><span class="line">@@ -1,2 +1,2 @@</span><br><span class="line">-Git is a version control system.</span><br><span class="line">-Git is free software.</span><br><span class="line">+Git is a distributed version control system.</span><br><span class="line">+Git is free software.</span><br><span class="line">\ No new</span><br></pre></td></tr></table></figure>

<h2 id="使用add-commit添加后再次使用git-status查看状态"><a href="#使用add-commit添加后再次使用git-status查看状态" class="headerlink" title="使用add, commit添加后再次使用git status查看状态"></a>使用<code>add, commit</code>添加后再次使用<code>git status</code>查看状态</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git add readme.md</span><br><span class="line"></span><br><span class="line">git status</span><br><span class="line">On branch master</span><br><span class="line">Changes to be committed:</span><br><span class="line">  (use <span class="string">&quot;git restore --staged &lt;file&gt;...&quot;</span> to unstage)</span><br><span class="line">    modified:   readme.md</span><br><span class="line"></span><br><span class="line">git commit -m <span class="string">&quot;add distributed&quot;</span></span><br><span class="line">[master 38d23dd] add distributed.</span><br><span class="line"> 1 file changed, 2 insertions(+), 2 deletions(-)</span><br><span class="line"></span><br><span class="line">git status</span><br><span class="line">On branch master</span><br><span class="line">nothing to commit, working tree clean</span><br></pre></td></tr></table></figure>

<h1 id="版本回退"><a href="#版本回退" class="headerlink" title="版本回退"></a>版本回退</h1><h2 id="使用git-log命令查看历史记录"><a href="#使用git-log命令查看历史记录" class="headerlink" title="使用git log命令查看历史记录"></a>使用<code>git log</code>命令查看历史记录</h2><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">commit abd5bd8a226f98ac9f26d81b2bd6d5fb4ca1e2d6 (HEAD -&gt; master)</span><br><span class="line">Author: jzhmcoo1 &lt;jzhmzlxcoo1@gmail.com&gt;</span><br><span class="line">Date:   Wed Jul 15 15:12:56 2020 +0800</span><br><span class="line"></span><br><span class="line">    append GPL</span><br><span class="line"></span><br><span class="line">commit 38d23dd5a097de1b742ff7894655b6cc2f11a5a8</span><br><span class="line">Author: jzhmcoo1 &lt;jzhmzlxcoo1@gmail.com&gt;</span><br><span class="line">Date:   Wed Jul 15 15:09:42 2020 +0800</span><br><span class="line"></span><br><span class="line">    add distributed.</span><br><span class="line"></span><br><span class="line">commit c81e9cb1ef762f10f29f05ce65dae99f95d4b9af</span><br><span class="line">Author: jzhmcoo1 &lt;jzhmzlxcoo1@gmail.com&gt;</span><br><span class="line">Date:   Wed Jul 15 14:59:19 2020 +0800</span><br><span class="line"></span><br><span class="line">    wrote a readme file.</span><br><span class="line">(END)</span><br></pre></td></tr></table></figure>

<p>其中<code>HEAD</code>执行的表示当前的版本，而<code>HEAD^</code>表示上个版本，<code>HEAD^^</code>表示上上个版本，前一百个版本写作<code>HEAD~100</code></p>
<h2 id="使用git-reset-hard-HEAD-回到上个版本"><a href="#使用git-reset-hard-HEAD-回到上个版本" class="headerlink" title="使用git reset --hard HEAD^回到上个版本"></a>使用<code>git reset --hard HEAD^</code>回到上个版本</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git reset --hard HEAD^</span><br><span class="line">HEAD is now at 38d23dd add distributed.</span><br></pre></td></tr></table></figure>

<h2 id="使用cat-readme-md查看回退后内容"><a href="#使用cat-readme-md查看回退后内容" class="headerlink" title="使用cat readme.md查看回退后内容"></a>使用<code>cat readme.md</code>查看回退后内容</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">cat readme.md</span><br><span class="line">Git is a distributed version control system.</span><br><span class="line">Git is free software.</span><br></pre></td></tr></table></figure>

<p>可以看到已经被还原了</p>
<h2 id="使用git-log查看回退后的记录"><a href="#使用git-log查看回退后的记录" class="headerlink" title="使用git log查看回退后的记录"></a>使用<code>git log</code>查看回退后的记录</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git <span class="built_in">log</span></span><br><span class="line">commit 38d23dd5a097de1b742ff7894655b6cc2f11a5a8 (HEAD -&gt; master)</span><br><span class="line">Author: jzhmcoo1 &lt;jzhmzlxcoo1@gmail.com&gt;</span><br><span class="line">Date:   Wed Jul 15 15:09:42 2020 +0800</span><br><span class="line"></span><br><span class="line">    add distributed.</span><br><span class="line"></span><br><span class="line">commit c81e9cb1ef762f10f29f05ce65dae99f95d4b9af</span><br><span class="line">Author: jzhmcoo1 &lt;jzhmzlxcoo1@gmail.com&gt;</span><br><span class="line">Date:   Wed Jul 15 14:59:19 2020 +0800</span><br><span class="line"></span><br><span class="line">    wrote a readme file.</span><br><span class="line">(END)</span><br></pre></td></tr></table></figure>

<p>会发现最新的版本<code>append GPL</code>不见了。</p>
<p>在没有关闭命令行的情况下，可以根据记录再次返回最新版本</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git reset --hard abd5bd8</span><br><span class="line">HEAD is now at abd5bd8 append GPL</span><br><span class="line"></span><br><span class="line">cat readme.md</span><br><span class="line">Git is a distributed version control system.</span><br><span class="line">Git is free software distributed under the GPL.</span><br></pre></td></tr></table></figure>

<p>果然又回到了最新版本</p>
<h2 id="使用-git-reflog查看每一次命令"><a href="#使用-git-reflog查看每一次命令" class="headerlink" title="使用 git reflog查看每一次命令"></a>使用 <code>git reflog</code>查看每一次命令</h2><p>如果不小心把命令行关了，那么只有通过这个方法进行回退最新版本</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git reflog</span><br><span class="line">abd5bd8 (HEAD -&gt; master) HEAD@&#123;0&#125;: reset: moving to abd5bd8</span><br><span class="line">38d23dd HEAD@&#123;1&#125;: reset: moving to 38d23dd</span><br><span class="line">38d23dd HEAD@&#123;2&#125;: reset: moving to HEAD^</span><br><span class="line">abd5bd8 (HEAD -&gt; master) HEAD@&#123;3&#125;: commit: append GPL</span><br><span class="line">38d23dd HEAD@&#123;4&#125;: commit: add distributed.</span><br><span class="line">c81e9cb HEAD@&#123;5&#125;: commit (initial): wrote a readme file.</span><br><span class="line">(END)</span><br></pre></td></tr></table></figure>

<p>我们可以找到最新版的<code>commit id</code>是<code>abd5bd8</code>，现在又可以使用<code>reset</code>命令回到最新版了</p>
<h1 id="工作区、暂存区、版本库"><a href="#工作区、暂存区、版本库" class="headerlink" title="工作区、暂存区、版本库"></a>工作区、暂存区、版本库</h1><h2 id="工作区（Working-Directory"><a href="#工作区（Working-Directory" class="headerlink" title="工作区（Working Directory)"></a>工作区（Working Directory)</h2><p>这里就是<code>Learn Git</code>这个目录</p>
<h2 id="版本库（Repository"><a href="#版本库（Repository" class="headerlink" title="版本库（Repository)"></a>版本库（Repository)</h2><p>工作区的隐藏目录<code>.git</code>是<code>Git</code>的版本库</p>
<p>版本库中的<code>Stage</code>即暂存区，使用<code>git add</code>命令的文件会先被加到此暂存区</p>
<p><code>git</code>还为我们自动创建了第一个分支<code>master</code>，以及一个指向<code>master</code>的指针<code>HEAD</code></p>
<p>目前来说<code>git commit</code>提交到的就是<code>master</code>分支上</p>
<h1 id="撤销修改"><a href="#撤销修改" class="headerlink" title="撤销修改"></a>撤销修改</h1><h2 id="使用git-restore-stage-readme-md回到add前的状态"><a href="#使用git-restore-stage-readme-md回到add前的状态" class="headerlink" title="使用git restore --stage readme.md回到add前的状态"></a>使用<code>git restore --stage readme.md</code>回到<code>add</code>前的状态</h2><p>假如现在的 <code>readme.md</code>被修改为</p>
<figure class="highlight md"><table><tr><td class="code"><pre><span class="line">Git is a distributed version control system.</span><br><span class="line">Git is free software distributed under the GPL.</span><br><span class="line">Git has a mutable index called stage.</span><br><span class="line">Git tracks changes of files.</span><br><span class="line">My stupid boss still prefers SVN.</span><br></pre></td></tr></table></figure>

<p>然后不小心已经使用<code>git add</code>提交到暂存区中了，</p>
<p>这个时候使用<code>git restore --stage readme.md</code></p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git restore --stage readme.md</span><br><span class="line"></span><br><span class="line"><span class="comment"># 使用 git status 查看</span></span><br><span class="line">git stauts</span><br><span class="line"></span><br><span class="line">On branch master</span><br><span class="line">Changes not staged <span class="keyword">for</span> commit:</span><br><span class="line">  (use <span class="string">&quot;git add &lt;file&gt;...&quot;</span> to update what will be committed)</span><br><span class="line">  (use <span class="string">&quot;git restore &lt;file&gt;...&quot;</span> to discard changes <span class="keyword">in</span> working directory)</span><br><span class="line">    modified:   readme.md</span><br><span class="line"></span><br><span class="line">no changes added to commit (use <span class="string">&quot;git add&quot;</span> and/or <span class="string">&quot;git commit -a&quot;</span>)</span><br></pre></td></tr></table></figure>

<p>可以看到已经恢复到<code>add</code>前的状态了</p>
<h2 id="使用git-restore-s-HEAD-1回到上个-commit版本"><a href="#使用git-restore-s-HEAD-1回到上个-commit版本" class="headerlink" title="使用git restore -s HEAD~1回到上个 commit版本"></a>使用<code>git restore -s HEAD~1</code>回到上个 commit版本</h2><p>如果我们不小心<code>add</code>还不小心<code>commit</code>了，就可以使用<code>git restore -s HEAD~1</code>回到上一个<code>commit</code>版本</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git restore -s HEAD~1 readme.md</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">git status</span><br><span class="line">On branch master</span><br><span class="line">Changes not staged <span class="keyword">for</span> commit:</span><br><span class="line">  (use <span class="string">&quot;git add &lt;file&gt;...&quot;</span> to update what will be committed)</span><br><span class="line">  (use <span class="string">&quot;git restore &lt;file&gt;...&quot;</span> to discard changes <span class="keyword">in</span> working directory)</span><br><span class="line">    modified:   readme.md</span><br><span class="line"></span><br><span class="line">no changes added to commit (use <span class="string">&quot;git add&quot;</span> and/or <span class="string">&quot;git commit -a&quot;</span>)</span><br></pre></td></tr></table></figure>

<p>可以看到我们回到了<code>add</code>前的状态</p>
<h1 id="删除文件"><a href="#删除文件" class="headerlink" title="删除文件"></a>删除文件</h1><h2 id="情况一，确定要删"><a href="#情况一，确定要删" class="headerlink" title="情况一，确定要删"></a>情况一，确定要删</h2><ol>
<li><p>先删除文件</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">rm readme.md</span><br><span class="line"></span><br><span class="line">git status</span><br><span class="line">On branch master</span><br><span class="line">Changes not staged <span class="keyword">for</span> commit:</span><br><span class="line">  (use <span class="string">&quot;git add/rm &lt;file&gt;...&quot;</span> to update what will be committed)</span><br><span class="line">  (use <span class="string">&quot;git restore &lt;file&gt;...&quot;</span> to discard changes <span class="keyword">in</span> working directory)</span><br><span class="line">    deleted:    readme.md</span><br><span class="line"></span><br><span class="line">no changes added to commit (use <span class="string">&quot;git add&quot;</span> and/or <span class="string">&quot;git commit -a&quot;</span>)</span><br></pre></td></tr></table></figure>
</li>
<li><p>从 Git 中也删除</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git rm readme.md</span><br><span class="line"></span><br><span class="line">git commit -m <span class="string">&quot;remove readme.md&quot;</span></span><br><span class="line">[master bb6883d] remove readme.md</span><br><span class="line"> 1 file changed, 5 deletions(-)</span><br><span class="line"> delete mode 100644 readme.md</span><br></pre></td></tr></table></figure>

</li>
</ol>
<h2 id="情况二，删错了"><a href="#情况二，删错了" class="headerlink" title="情况二，删错了"></a>情况二，删错了</h2><ol>
<li>使用<code>git restore -s HEAD~1 readme.md</code>回到上个版本</li>
</ol>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git restore -s HEAD~1 readme.md</span><br><span class="line"></span><br><span class="line">cat readme.md</span><br><span class="line">Git is a distributed version control system.</span><br><span class="line">Git is free software distributed under the GPL.</span><br><span class="line">Git has a mutable index called stage.</span><br><span class="line">Git tracks changes of files.</span><br><span class="line">My stupid boss still prefers SVN.</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>使用 <code>git reset --hard &lt;commit id&gt;</code>回退到任意之前版本</li>
</ol>
<h1 id="添加远程仓库"><a href="#添加远程仓库" class="headerlink" title="添加远程仓库"></a>添加远程仓库</h1><h2 id="（如果没有设置-ssh）"><a href="#（如果没有设置-ssh）" class="headerlink" title="（如果没有设置 ssh）"></a>（如果没有设置 ssh）</h2><p>如果没有设置过 SSH KEY，主目录应该没有<code>.ssh</code>目录，如果没有可以使用以下命令创建</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">ssh-keygen -t rsa -C <span class="string">&quot;youremail@example.com&quot;</span></span><br></pre></td></tr></table></figure>

<p>具体操作步骤省略</p>
<h2 id="在Github上新建一个仓库"><a href="#在Github上新建一个仓库" class="headerlink" title="在Github上新建一个仓库"></a>在<code>Github</code>上新建一个仓库</h2><p>起名可以为<code>LearnGit</code>其他保持默认</p>
<img src= "/img/loading.gif" data-lazy-src="https://gitee.com/jzhmcoo1/jzhmcoo1picrepo/raw/master/img/learn-git-remote.png" title="" alt="" data-align="center">

<h2 id="使用给的提示命令，在本地命令行下输入以上代码"><a href="#使用给的提示命令，在本地命令行下输入以上代码" class="headerlink" title="使用给的提示命令，在本地命令行下输入以上代码"></a>使用给的提示命令，在本地命令行下输入以上代码</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git remote add origin https://github.com/jzhmcoo1/LearnGit.git</span><br><span class="line">git push -u origin master</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">Enumerating objects: 14, <span class="keyword">done</span>.</span><br><span class="line">Counting objects: 100% (14/14), <span class="keyword">done</span>.</span><br><span class="line">Delta compression using up to 8 threads</span><br><span class="line">Compressing objects: 100% (9/9), <span class="keyword">done</span>.</span><br><span class="line">Writing objects: 100% (14/14), 1.19 KiB | 1.19 MiB/s, <span class="keyword">done</span>.</span><br><span class="line">Total 14 (delta 2), reused 0 (delta 0)</span><br><span class="line">remote: Resolving deltas: 100% (2/2), <span class="keyword">done</span>.</span><br><span class="line">To https://github.com/jzhmcoo1/LearnGit.git</span><br><span class="line"> * [new branch]      master -&gt; master</span><br><span class="line">Branch <span class="string">&#x27;master&#x27;</span> <span class="built_in">set</span> up to track remote branch <span class="string">&#x27;master&#x27;</span> from <span class="string">&#x27;origin&#x27;</span>.</span><br></pre></td></tr></table></figure>

<p>其中，第一次进行推送使用<code>git push -u</code>参数，会把本地的<code>master</code>分支内容推送到远程的<code>master</code>分支中，还会将他们关联起来，以后使用<code>push</code>命令时，可以简化为<code>git push origin master</code></p>
<h1 id="从远程库克隆"><a href="#从远程库克隆" class="headerlink" title="从远程库克隆"></a>从远程库克隆</h1><p>我们可以先把这个目录直接删掉，然后从刚才的项目库进行克隆</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">rm -rf LearnGit</span><br><span class="line"></span><br><span class="line">git <span class="built_in">clone</span> git@github.com:jzhmcoo1/LearnGit.git</span><br></pre></td></tr></table></figure>

<h1 id="分支管理"><a href="#分支管理" class="headerlink" title="分支管理"></a>分支管理</h1><h2 id="创建并切换到dev分支"><a href="#创建并切换到dev分支" class="headerlink" title="创建并切换到dev分支"></a>创建并切换到<code>dev</code>分支</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git checkout -b dev</span><br><span class="line">Switched to a new branch <span class="string">&#x27;dev&#x27;</span></span><br></pre></td></tr></table></figure>

<p><code>git checkout</code>命令加上<code>-b</code>表示创建并且切换，相当于</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git branch dev</span><br><span class="line">git checkout dev</span><br></pre></td></tr></table></figure>

<h2 id="使用git-branch查看当前分支"><a href="#使用git-branch查看当前分支" class="headerlink" title="使用git branch查看当前分支"></a>使用<code>git branch</code>查看当前分支</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git branch</span><br><span class="line">* dev</span><br><span class="line">  master</span><br></pre></td></tr></table></figure>

<p>带星号表示当前分支</p>
<h2 id="在新分支上进行提交"><a href="#在新分支上进行提交" class="headerlink" title="在新分支上进行提交"></a>在新分支上进行提交</h2><p>新建一个<code>readme.txt</code>文件，并保存</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">Creating a new branch is quick.</span><br></pre></td></tr></table></figure>

<p>然后<code>add</code>+<code>commit</code></p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git add readme.txt</span><br><span class="line">git commit -m <span class="string">&quot;branch test&quot;</span></span><br><span class="line"></span><br><span class="line">[dev 1cedf1e] branch <span class="built_in">test</span></span><br><span class="line"> 1 file changed, 1 insertion(+)</span><br><span class="line"> create mode 100644 readme.txt</span><br></pre></td></tr></table></figure>

<h2 id="将分支切回master"><a href="#将分支切回master" class="headerlink" title="将分支切回master"></a>将分支切回<code>master</code></h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git checkout master</span><br><span class="line"></span><br><span class="line">Switched to branch <span class="string">&#x27;master&#x27;</span></span><br><span class="line">Your branch is up to date with <span class="string">&#x27;origin/master&#x27;</span>.</span><br></pre></td></tr></table></figure>

<p>输入<code>ll</code>发现没有<code>readme.txt</code>文件</p>
<h2 id="使用git-merge-dev将dev合并到master分支上"><a href="#使用git-merge-dev将dev合并到master分支上" class="headerlink" title="使用git merge dev将dev合并到master分支上"></a>使用<code>git merge dev</code>将<code>dev</code>合并到<code>master</code>分支上</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git merge dev</span><br><span class="line"></span><br><span class="line">Updating bb6883d..1cedf1e</span><br><span class="line">Fast-forward</span><br><span class="line"> readme.txt | 1 +</span><br><span class="line"> 1 file changed, 1 insertion(+)</span><br><span class="line"> create mode 100644 readme.txt</span><br></pre></td></tr></table></figure>

<p><code>Fast-forward</code>表示这次合并是“快进模式”，就是直接让<code>master</code>指向了<code>dev</code>当前的提交，所以合并速度很快，但并不是每次合并都能快进。</p>
<h2 id="合并完成，可以删除dev分支"><a href="#合并完成，可以删除dev分支" class="headerlink" title="合并完成，可以删除dev分支"></a>合并完成，可以删除<code>dev</code>分支</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git branch -d dev</span><br><span class="line"></span><br><span class="line">Deleted branch dev (was 1cedf1e).</span><br></pre></td></tr></table></figure>

<h2 id="使用git-branch查看结果"><a href="#使用git-branch查看结果" class="headerlink" title="使用git branch查看结果"></a>使用<code>git branch</code>查看结果</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git branch</span><br><span class="line">* master</span><br></pre></td></tr></table></figure>

<h2 id="使用git-switch切换分支"><a href="#使用git-switch切换分支" class="headerlink" title="使用git switch切换分支"></a>使用<code>git switch</code>切换分支</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git switch -c dev <span class="comment"># 新建并切换到 dev 分支</span></span><br><span class="line"></span><br><span class="line">git switch master <span class="comment"># 切换到 master 分支</span></span><br></pre></td></tr></table></figure>

<h2 id="解决冲突"><a href="#解决冲突" class="headerlink" title="解决冲突"></a>解决冲突</h2><p>当Git 无法自动合并分支时，需要首先解决手动冲突。解决冲突后再提交合并。</p>
<h3 id="创建新分支feature1"><a href="#创建新分支feature1" class="headerlink" title="创建新分支feature1"></a>创建新分支<code>feature1</code></h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git switch -c feature1</span><br><span class="line">Switched to a new branch <span class="string">&#x27;feature1&#x27;</span></span><br></pre></td></tr></table></figure>

<h3 id="新分支修改-readme-txt"><a href="#新分支修改-readme-txt" class="headerlink" title="新分支修改 readme.txt"></a>新分支修改 <code>readme.txt</code></h3><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">Creating a new branch is quick AND simple.</span><br></pre></td></tr></table></figure>

<h3 id="新分支上提交"><a href="#新分支上提交" class="headerlink" title="新分支上提交"></a>新分支上提交</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git add readme.txt</span><br><span class="line"></span><br><span class="line">git commit -m <span class="string">&quot;AND simple&quot;</span></span><br><span class="line">[feature1 1843c86] AND simple</span><br><span class="line"> 1 file changed, 1 insertion(+), 1 deletion(-)</span><br></pre></td></tr></table></figure>

<h3 id="切换到master分支"><a href="#切换到master分支" class="headerlink" title="切换到master分支"></a>切换到<code>master</code>分支</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git switch master</span><br><span class="line">Switched to branch <span class="string">&#x27;master&#x27;</span></span><br><span class="line">Your branch is ahead of <span class="string">&#x27;origin/master&#x27;</span> by 1 commit.</span><br><span class="line">  (use <span class="string">&quot;git push&quot;</span> to publish your <span class="built_in">local</span> commits)</span><br></pre></td></tr></table></figure>

<h3 id="修改master分支中的readme-txt文件"><a href="#修改master分支中的readme-txt文件" class="headerlink" title="修改master分支中的readme.txt文件"></a>修改<code>master</code>分支中的<code>readme.txt</code>文件</h3><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">Creating a new branch is quick &amp; simple.</span><br></pre></td></tr></table></figure>

<h3 id="在master分支中提交"><a href="#在master分支中提交" class="headerlink" title="在master分支中提交"></a>在<code>master</code>分支中提交</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git add readme.txt</span><br><span class="line">git commit -m <span class="string">&quot;&amp; simple&quot;</span></span><br><span class="line">[master a737806] &amp; simple</span><br><span class="line"> 1 file changed, 1 insertion(+), 1 deletion(-)</span><br></pre></td></tr></table></figure>

<h3 id="尝试merge-feature1"><a href="#尝试merge-feature1" class="headerlink" title="尝试merge feature1"></a>尝试<code>merge feature1</code></h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git merge feature1</span><br><span class="line">Auto-merging readme.txt</span><br><span class="line">CONFLICT (content): Merge conflict <span class="keyword">in</span> readme.txt</span><br><span class="line">Automatic merge failed; fix conflicts and <span class="keyword">then</span> commit the result.</span><br></pre></td></tr></table></figure>

<h3 id="使用git-status查看冲突文件"><a href="#使用git-status查看冲突文件" class="headerlink" title="使用git status查看冲突文件"></a>使用<code>git status</code>查看冲突文件</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git status</span><br><span class="line">On branch master</span><br><span class="line">Your branch is ahead of <span class="string">&#x27;origin/master&#x27;</span> by 2 commits.</span><br><span class="line">  (use <span class="string">&quot;git push&quot;</span> to publish your <span class="built_in">local</span> commits)</span><br><span class="line"></span><br><span class="line">You have unmerged paths.</span><br><span class="line">  (fix conflicts and run <span class="string">&quot;git commit&quot;</span>)</span><br><span class="line">  (use <span class="string">&quot;git merge --abort&quot;</span> to abort the merge)</span><br><span class="line"></span><br><span class="line">Unmerged paths:</span><br><span class="line">  (use <span class="string">&quot;git add &lt;file&gt;...&quot;</span> to mark resolution)</span><br><span class="line">    both modified:   readme.txt</span><br><span class="line"></span><br><span class="line">no changes added to commit (use <span class="string">&quot;git add&quot;</span> and/or <span class="string">&quot;git commit -a&quot;</span>)</span><br></pre></td></tr></table></figure>

<h3 id="使用cat查看冲突内容"><a href="#使用cat查看冲突内容" class="headerlink" title="使用cat查看冲突内容"></a>使用<code>cat</code>查看冲突内容</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">cat readme.txt</span><br><span class="line"></span><br><span class="line">&lt;&lt;&lt;&lt;&lt;&lt;&lt; <span class="string">HEAD</span></span><br><span class="line"><span class="string">Creating a new branch is quick &amp; simple.</span></span><br><span class="line"><span class="string">=======</span></span><br><span class="line"><span class="string">Creating a new branch is quick AND simple.</span></span><br><span class="line"><span class="string">&gt;&gt;&gt;&gt;&gt;&gt;&gt; feature1</span></span><br></pre></td></tr></table></figure>

<h3 id="手动修改冲突并提交"><a href="#手动修改冲突并提交" class="headerlink" title="手动修改冲突并提交"></a>手动修改冲突并提交</h3><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">Creating a new branch is quick and simple.</span><br></pre></td></tr></table></figure>

<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git add readme.txt</span><br><span class="line">git commit -m <span class="string">&quot;conflict fixed&quot;</span></span><br><span class="line">[master 20f6131] conflict fixed</span><br></pre></td></tr></table></figure>

<h3 id="使用git-log查看分支的合并情况"><a href="#使用git-log查看分支的合并情况" class="headerlink" title="使用git log查看分支的合并情况"></a>使用<code>git log</code>查看分支的合并情况</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">$ git <span class="built_in">log</span> --graph --pretty=oneline --abbrev-commit</span><br><span class="line">*   20f6131 (HEAD -&gt; master) conflict fixed</span><br><span class="line">|\</span><br><span class="line">| * 1843c86 (feature1) AND simple</span><br><span class="line">* | a737806 &amp; simple</span><br><span class="line">|/</span><br><span class="line">* 1cedf1e branch <span class="built_in">test</span></span><br><span class="line">* bb6883d (origin/master, origin/HEAD) remove readme.md</span><br><span class="line">* ab80813 StupidBoss</span><br><span class="line">* abd5bd8 append GPL</span><br><span class="line">* 38d23dd add distributed.</span><br><span class="line">* c81e9cb wrote a readme file.</span><br></pre></td></tr></table></figure>

<h3 id="最后可以删除feature1分支"><a href="#最后可以删除feature1分支" class="headerlink" title="最后可以删除feature1分支"></a>最后可以删除<code>feature1</code>分支</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git branch -d feature1</span><br></pre></td></tr></table></figure>

<h1 id="分支管理策略"><a href="#分支管理策略" class="headerlink" title="分支管理策略"></a>分支管理策略</h1><blockquote>
<p>通常，合并分支时，如果可能，Git 会使用<code>Fast Forward</code>模式，但这种模式下，删除分支后，会丢掉分支信息。</p>
<p>如果要强制禁用<code>Fast forward</code>模式，Git就会在merge时生成一个新的commit，这样，从分支历史上就可以看出分支信息。</p>
</blockquote>
<h2 id="使用-no-ff的方式合并"><a href="#使用-no-ff的方式合并" class="headerlink" title="使用--no-ff的方式合并"></a>使用<code>--no-ff</code>的方式合并</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">$ git merge --no-ff -m <span class="string">&quot;merge with no-ff&quot;</span> dev</span><br><span class="line">Merge made by the <span class="string">&#x27;recursive&#x27;</span> strategy.</span><br><span class="line"> readme.txt | 1 +</span><br><span class="line"> 1 file changed, 1 insertion(+)</span><br></pre></td></tr></table></figure>

<h2 id="策略"><a href="#策略" class="headerlink" title="策略"></a>策略</h2><p>按照几个基本原则：</p>
<ol>
<li><p><code>master</code>分支应该是稳定上线的</p>
</li>
<li><p>在<code>dev</code>分支上进行开发工作，再把<code>dev</code>分支合并到<code>merge</code>上</p>
</li>
<li><p>每个人都在<code>dev</code>分支上进行开发，每个人都有自己的分支，时不时往<code>dev</code>分支进行合并</p>
</li>
</ol>
<h1 id="Bug分支"><a href="#Bug分支" class="headerlink" title="Bug分支"></a><code>Bug</code>分支</h1><p>准备修复<code>bug</code>前，先要把自己的工作状态保存起来</p>
<h2 id="使用git-stash保存当前工作现场"><a href="#使用git-stash保存当前工作现场" class="headerlink" title="使用git stash保存当前工作现场"></a>使用<code>git stash</code>保存当前工作现场</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git stash</span><br><span class="line">Saved working directory and index state WIP on master: 20f6131 conflict fixed</span><br></pre></td></tr></table></figure>

<h2 id="确定要修复bug的分支"><a href="#确定要修复bug的分支" class="headerlink" title="确定要修复bug的分支"></a>确定要修复<code>bug</code>的分支</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git switch master</span><br><span class="line">git switch -c issue-101 <span class="comment"># 从 master 分支创建了一个临时分支</span></span><br></pre></td></tr></table></figure>

<h2 id="修复bug后进行提交合并"><a href="#修复bug后进行提交合并" class="headerlink" title="修复bug后进行提交合并"></a>修复<code>bug</code>后进行提交合并</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git add readme.txt</span><br><span class="line">git commit -m <span class="string">&quot;fix bug 101&quot;</span></span><br></pre></td></tr></table></figure>

<h2 id="修复完成，切换到master分支合并，然后删除issue"><a href="#修复完成，切换到master分支合并，然后删除issue" class="headerlink" title="修复完成，切换到master分支合并，然后删除issue"></a>修复完成，切换到<code>master</code>分支合并，然后删除<code>issue</code></h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git switch master</span><br><span class="line">git merge --no-ff -m <span class="string">&quot;merged bug fix 101&quot;</span> issue-101</span><br></pre></td></tr></table></figure>

<h2 id="恢复工作现场"><a href="#恢复工作现场" class="headerlink" title="恢复工作现场"></a>恢复工作现场</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git switch dev</span><br><span class="line">git status</span><br></pre></td></tr></table></figure>

<p>使用<code>git stash list</code>查看</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git stash list</span><br><span class="line">stash@&#123;0&#125;: WIP on dev: f52c633 add merge</span><br></pre></td></tr></table></figure>

<ol>
<li><p>使用<code>git stash apply</code>恢复，需要手动使用<code>git stash drop</code>删除</p>
</li>
<li><p>使用<code>git stash pop</code>恢复，同时自动删除了<code>stash</code>内容</p>
</li>
</ol>
<h2 id="将master修复的bug合并到dev上"><a href="#将master修复的bug合并到dev上" class="headerlink" title="将master修复的bug合并到dev上"></a>将<code>master</code>修复的<code>bug</code>合并到<code>dev</code>上</h2><p>使用<code>git cherry-pick</code>将一个特定的提交复制到当前分支</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git branch</span><br><span class="line">* dev</span><br><span class="line">  master</span><br><span class="line">git cherry-pick 4c805e2</span><br><span class="line">[master 1d4b803] fix bug 101</span><br><span class="line"> 1 file changed, 1 insertion(+), 1 deletion(-)</span><br></pre></td></tr></table></figure>

<h1 id="Feature分支"><a href="#Feature分支" class="headerlink" title="Feature分支"></a><code>Feature</code>分支</h1><p>每添加一个新的功能，最好新建一个<code>feature</code>分支，在上面的开发完成后，合并，最后删除该<code>feature</code>分支</p>
<h2 id="新建分支"><a href="#新建分支" class="headerlink" title="新建分支"></a>新建分支</h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git switch -c feature-vulcan</span><br></pre></td></tr></table></figure>

<h2 id="feature分支与dev分支合并"><a href="#feature分支与dev分支合并" class="headerlink" title="feature分支与dev分支合并"></a><code>feature</code>分支与<code>dev</code>分支合并</h2><p>一切没问题后，切换到<code>dev</code>分支并合并</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git switch dev</span><br><span class="line">git merge feature-vulcan</span><br></pre></td></tr></table></figure>

<h3 id="若想要删除未合并的分支"><a href="#若想要删除未合并的分支" class="headerlink" title="若想要删除未合并的分支"></a>若想要删除未合并的分支</h3><p>使用<code>git branch -D feature-vulcan</code></p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git branch -D feature-vulcan</span><br></pre></td></tr></table></figure>

<h1 id="多人协作开发"><a href="#多人协作开发" class="headerlink" title="多人协作开发"></a>多人协作开发</h1><p>多人协作的工作模式通常是：</p>
<ol>
<li><p>尝试使用<code>git push origin &lt;branch-name&gt;</code>推送自己的修改；</p>
</li>
<li><p>如果推送失败，使用<code>git pull</code>试图合并；</p>
</li>
<li><p>如果合并有冲突，则解决冲突，并在本地提交；</p>
</li>
<li><p>没有冲突或者解决掉冲突以后，再用<code>git push origin &lt;branch-name&gt;</code>推送成功；</p>
</li>
</ol>
<p>如果<code>git pull</code>提示<code>no tracking information</code>，说明本地分支和远程分支的链接关系没有创建，使用命令<code>git branch --set-upstream-to &lt;branch-name&gt; origin/&lt;branch-name&gt;</code></p>
<h1 id="Rebase操作"><a href="#Rebase操作" class="headerlink" title="Rebase操作"></a><code>Rebase</code>操作</h1><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git rebase</span><br></pre></td></tr></table></figure>

<ul>
<li><p>操作特点：把分叉的提交历史“整理”成一条直线，看上去更直观。缺点是本地的分支提交已经被修改过了</p>
</li>
<li><p>rebase的目的是使得我们在查看历史提交的变化时更容易，因为分叉的提交需要三方对比。</p>
</li>
</ul>
<h1 id="标签管理"><a href="#标签管理" class="headerlink" title="标签管理"></a>标签管理</h1><blockquote>
<p>发布一个版本时，我们通常先在版本库中打一个标签（tag），这样，就唯一确定了打标签时刻的版本。将来无论什么时候，取某个标签的版本，就是把那个打标签的时刻的历史版本取出来。所以，标签也是版本库的一个快照。</p>
</blockquote>
<h2 id="创建标签"><a href="#创建标签" class="headerlink" title="创建标签"></a>创建标签</h2><ol>
<li><p>切换到需要打标签的分支上</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git switch master</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用<code>git tag &lt;name&gt;</code>打一个新标签</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git tag v1.0</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用<code>git tag</code>查看所有标签</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git tag</span><br></pre></td></tr></table></figure>
</li>
<li><p>使用<code>git tag &lt;tagname&gt; &lt;commit id&gt;</code>可以对指定的<code>commit</code>打上<code>tag</code></p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git tag v0.9 f52c633</span><br></pre></td></tr></table></figure>
</li>
<li><p>标签是按照字母排序列出的。<code>git show &lt;tagname&gt;</code>可以查看标签信息</p>
<p>可以创建带有说明的标签，使用<code>-a</code>指定标签名，<code>-m</code>指定说明文字</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git tag -a v0.1 -m <span class="string">&quot;version 0.1 released&quot;</span> 1094adb</span><br></pre></td></tr></table></figure>

</li>
</ol>
<h2 id="操作标签"><a href="#操作标签" class="headerlink" title="操作标签"></a>操作标签</h2><ol>
<li><p>删除标签</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git tag -d v0.1</span><br></pre></td></tr></table></figure>
</li>
<li><p>因为创建的标签都只存储在本地，不会自动推送到远程。所以，打错的标签可以在本地安全删除。</p>
</li>
<li><p>如果要推送某个标签到远程，使用命令<code>git push origin &lt;tagname&gt;</code></p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git push origin &lt;tagname&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><p>一次性推送所有本地标签</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git push origin --tags</span><br></pre></td></tr></table></figure>
</li>
<li><p>从远程删除标签</p>
<p>先从本地删除：</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git tag -d &lt;tagname&gt;</span><br></pre></td></tr></table></figure>

<p>然后从远程删除</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">git push origin :refs/tags/&lt;tagname&gt;</span><br></pre></td></tr></table></figure>

</li>
</ol>
<h1 id="Git的网站"><a href="#Git的网站" class="headerlink" title="Git的网站"></a><code>Git</code>的网站</h1><ul>
<li><p><a target="_blank" rel="noopener" href="https://gitee.com/liaoxuefeng/learn-java/raw/master/teach/git-cheatsheet.pdf">Git Cheat Sheet</a></p>
</li>
<li><p><a target="_blank" rel="noopener" href="http://git-scm.com/">Git 官方网站</a></p>
</li>
</ul>
<h1 id="2020-9-20更新"><a href="#2020-9-20更新" class="headerlink" title="2020.9.20更新"></a>2020.9.20更新</h1><h2 id="git删除远程文件（保留本地）"><a href="#git删除远程文件（保留本地）" class="headerlink" title="git删除远程文件（保留本地）"></a>git删除远程文件（保留本地）</h2><h3 id="预览（不删除）"><a href="#预览（不删除）" class="headerlink" title="预览（不删除）"></a>预览（不删除）</h3><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">git rm -r -n --cached 文件/文件夹名称 </span><br></pre></td></tr></table></figure>

<h3 id="确定无误后删除文件"><a href="#确定无误后删除文件" class="headerlink" title="确定无误后删除文件"></a>确定无误后删除文件</h3><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">git rm -r --cached 文件/文件夹名称</span><br></pre></td></tr></table></figure>

<h3 id="提交并推送至远程服务器"><a href="#提交并推送至远程服务器" class="headerlink" title="提交并推送至远程服务器"></a>提交并推送至远程服务器</h3><figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">git commit -m &quot;提交说明&quot;</span><br><span class="line">git push origin master</span><br></pre></td></tr></table></figure>

</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">lixing</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://www.lihangzhu.com/2020/07/18/LearnGit/">https://www.lihangzhu.com/2020/07/18/LearnGit/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://www.lihangzhu.com" target="_blank">jzhmcoo1</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Git/">Git</a></div><div class="post_share"><div class="social-share" data-image="https://gitee.com/jzhmcoo1/jzhmcoo1picrepo/raw/master/img/git.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2020/07/21/JavaScript-RegExp/"><img class="prev-cover" data-lazy-src="https://gitee.com/jzhmcoo1/jzhmcoo1picrepo/raw/master/img/javascriptlogo.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">JavaScript学习笔记——正则表达式</div></div></a></div><div class="next-post pull-right"><a href="/2020/07/12/Leetcode-1144/"><img class="next-cover" data-lazy-src="https://gitee.com/jzhmcoo1/jzhmcoo1picrepo/raw/master/img/LeetCodeLogo.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Leetcode-1144</div></div></a></div></nav><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" data-lazy-src="https://jzhmcoo1-1258918430.cos.ap-shanghai.myqcloud.com/markdown/avatar.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">lixing</div><div class="author-info__description">👨🏻‍💻 好好学习，天天敲代码 👩🏻‍💻</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">36</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">37</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/jzhmcoo1"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/jzhmcoo1" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:jzhmzlxocoo1@gmail.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="/atom.xml" target="_blank" title="RSS"><i class="fa fa-rss"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">真正的大师,永远都怀着一颗学徒的心</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%89%8D%E8%A8%80"><span class="toc-number">1.</span> <span class="toc-text">前言</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E7%89%88%E6%9C%AC%E5%BA%93"><span class="toc-number">2.</span> <span class="toc-text">创建版本库</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E7%A9%BA%E6%96%87%E4%BB%B6%E5%A4%B9"><span class="toc-number">2.1.</span> <span class="toc-text">创建空文件夹</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8git-init%E5%91%BD%E4%BB%A4%E5%88%9D%E5%A7%8B%E5%8C%96git%E4%BB%93%E5%BA%93"><span class="toc-number">2.2.</span> <span class="toc-text">使用git init命令初始化git仓库</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8la%E5%91%BD%E4%BB%A4%E6%9F%A5%E7%9C%8B%E7%9B%AE%E5%BD%95"><span class="toc-number">2.3.</span> <span class="toc-text">使用la命令查看目录</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9C%A8%E6%A0%B9%E7%9B%AE%E5%BD%95%E4%B8%8B%E5%88%9B%E5%BB%BA%E6%96%B0%E6%96%87%E4%BB%B6readme-md"><span class="toc-number">2.4.</span> <span class="toc-text">在根目录下创建新文件readme.md</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8git-add-lt-%E6%96%87%E4%BB%B6%E5%90%8D-gt-%E5%B0%86%E6%96%87%E4%BB%B6%E6%B7%BB%E5%8A%A0%E5%88%B0%E6%9A%82%E5%AD%98%E5%8C%BA"><span class="toc-number">2.5.</span> <span class="toc-text">使用git add &lt;文件名&gt;将文件添加到暂存区</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8git-commit%E5%B0%86%E6%96%87%E4%BB%B6%E6%8F%90%E4%BA%A4%E5%88%B0%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93"><span class="toc-number">2.6.</span> <span class="toc-text">使用git commit将文件提交到本地仓库</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%8E%86%E5%8F%B2%E8%AE%B0%E5%BD%95%E7%AE%A1%E7%90%86"><span class="toc-number">3.</span> <span class="toc-text">历史记录管理</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8git-status%E6%9F%A5%E7%9C%8B%E4%BB%93%E5%BA%93%E5%BD%93%E5%89%8D%E7%8A%B6%E6%80%81"><span class="toc-number">3.1.</span> <span class="toc-text">使用git status查看仓库当前状态</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8git-diff-lt-%E6%96%87%E4%BB%B6%E5%90%8D-gt-%E6%9F%A5%E7%9C%8B%E5%85%B7%E4%BD%93%E4%BF%AE%E6%94%B9%E5%86%85%E5%AE%B9"><span class="toc-number">3.2.</span> <span class="toc-text">使用git diff &lt;文件名&gt;查看具体修改内容</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8add-commit%E6%B7%BB%E5%8A%A0%E5%90%8E%E5%86%8D%E6%AC%A1%E4%BD%BF%E7%94%A8git-status%E6%9F%A5%E7%9C%8B%E7%8A%B6%E6%80%81"><span class="toc-number">3.3.</span> <span class="toc-text">使用add, commit添加后再次使用git status查看状态</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%89%88%E6%9C%AC%E5%9B%9E%E9%80%80"><span class="toc-number">4.</span> <span class="toc-text">版本回退</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8git-log%E5%91%BD%E4%BB%A4%E6%9F%A5%E7%9C%8B%E5%8E%86%E5%8F%B2%E8%AE%B0%E5%BD%95"><span class="toc-number">4.1.</span> <span class="toc-text">使用git log命令查看历史记录</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8git-reset-hard-HEAD-%E5%9B%9E%E5%88%B0%E4%B8%8A%E4%B8%AA%E7%89%88%E6%9C%AC"><span class="toc-number">4.2.</span> <span class="toc-text">使用git reset --hard HEAD^回到上个版本</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8cat-readme-md%E6%9F%A5%E7%9C%8B%E5%9B%9E%E9%80%80%E5%90%8E%E5%86%85%E5%AE%B9"><span class="toc-number">4.3.</span> <span class="toc-text">使用cat readme.md查看回退后内容</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8git-log%E6%9F%A5%E7%9C%8B%E5%9B%9E%E9%80%80%E5%90%8E%E7%9A%84%E8%AE%B0%E5%BD%95"><span class="toc-number">4.4.</span> <span class="toc-text">使用git log查看回退后的记录</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8-git-reflog%E6%9F%A5%E7%9C%8B%E6%AF%8F%E4%B8%80%E6%AC%A1%E5%91%BD%E4%BB%A4"><span class="toc-number">4.5.</span> <span class="toc-text">使用 git reflog查看每一次命令</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%B7%A5%E4%BD%9C%E5%8C%BA%E3%80%81%E6%9A%82%E5%AD%98%E5%8C%BA%E3%80%81%E7%89%88%E6%9C%AC%E5%BA%93"><span class="toc-number">5.</span> <span class="toc-text">工作区、暂存区、版本库</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B7%A5%E4%BD%9C%E5%8C%BA%EF%BC%88Working-Directory"><span class="toc-number">5.1.</span> <span class="toc-text">工作区（Working Directory)</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%89%88%E6%9C%AC%E5%BA%93%EF%BC%88Repository"><span class="toc-number">5.2.</span> <span class="toc-text">版本库（Repository)</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%92%A4%E9%94%80%E4%BF%AE%E6%94%B9"><span class="toc-number">6.</span> <span class="toc-text">撤销修改</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8git-restore-stage-readme-md%E5%9B%9E%E5%88%B0add%E5%89%8D%E7%9A%84%E7%8A%B6%E6%80%81"><span class="toc-number">6.1.</span> <span class="toc-text">使用git restore --stage readme.md回到add前的状态</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8git-restore-s-HEAD-1%E5%9B%9E%E5%88%B0%E4%B8%8A%E4%B8%AA-commit%E7%89%88%E6%9C%AC"><span class="toc-number">6.2.</span> <span class="toc-text">使用git restore -s HEAD~1回到上个 commit版本</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E6%96%87%E4%BB%B6"><span class="toc-number">7.</span> <span class="toc-text">删除文件</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%83%85%E5%86%B5%E4%B8%80%EF%BC%8C%E7%A1%AE%E5%AE%9A%E8%A6%81%E5%88%A0"><span class="toc-number">7.1.</span> <span class="toc-text">情况一，确定要删</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%83%85%E5%86%B5%E4%BA%8C%EF%BC%8C%E5%88%A0%E9%94%99%E4%BA%86"><span class="toc-number">7.2.</span> <span class="toc-text">情况二，删错了</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%B7%BB%E5%8A%A0%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93"><span class="toc-number">8.</span> <span class="toc-text">添加远程仓库</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%EF%BC%88%E5%A6%82%E6%9E%9C%E6%B2%A1%E6%9C%89%E8%AE%BE%E7%BD%AE-ssh%EF%BC%89"><span class="toc-number">8.1.</span> <span class="toc-text">（如果没有设置 ssh）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9C%A8Github%E4%B8%8A%E6%96%B0%E5%BB%BA%E4%B8%80%E4%B8%AA%E4%BB%93%E5%BA%93"><span class="toc-number">8.2.</span> <span class="toc-text">在Github上新建一个仓库</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8%E7%BB%99%E7%9A%84%E6%8F%90%E7%A4%BA%E5%91%BD%E4%BB%A4%EF%BC%8C%E5%9C%A8%E6%9C%AC%E5%9C%B0%E5%91%BD%E4%BB%A4%E8%A1%8C%E4%B8%8B%E8%BE%93%E5%85%A5%E4%BB%A5%E4%B8%8A%E4%BB%A3%E7%A0%81"><span class="toc-number">8.3.</span> <span class="toc-text">使用给的提示命令，在本地命令行下输入以上代码</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BB%8E%E8%BF%9C%E7%A8%8B%E5%BA%93%E5%85%8B%E9%9A%86"><span class="toc-number">9.</span> <span class="toc-text">从远程库克隆</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%88%86%E6%94%AF%E7%AE%A1%E7%90%86"><span class="toc-number">10.</span> <span class="toc-text">分支管理</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E5%B9%B6%E5%88%87%E6%8D%A2%E5%88%B0dev%E5%88%86%E6%94%AF"><span class="toc-number">10.1.</span> <span class="toc-text">创建并切换到dev分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8git-branch%E6%9F%A5%E7%9C%8B%E5%BD%93%E5%89%8D%E5%88%86%E6%94%AF"><span class="toc-number">10.2.</span> <span class="toc-text">使用git branch查看当前分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9C%A8%E6%96%B0%E5%88%86%E6%94%AF%E4%B8%8A%E8%BF%9B%E8%A1%8C%E6%8F%90%E4%BA%A4"><span class="toc-number">10.3.</span> <span class="toc-text">在新分支上进行提交</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B0%86%E5%88%86%E6%94%AF%E5%88%87%E5%9B%9Emaster"><span class="toc-number">10.4.</span> <span class="toc-text">将分支切回master</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8git-merge-dev%E5%B0%86dev%E5%90%88%E5%B9%B6%E5%88%B0master%E5%88%86%E6%94%AF%E4%B8%8A"><span class="toc-number">10.5.</span> <span class="toc-text">使用git merge dev将dev合并到master分支上</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%90%88%E5%B9%B6%E5%AE%8C%E6%88%90%EF%BC%8C%E5%8F%AF%E4%BB%A5%E5%88%A0%E9%99%A4dev%E5%88%86%E6%94%AF"><span class="toc-number">10.6.</span> <span class="toc-text">合并完成，可以删除dev分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8git-branch%E6%9F%A5%E7%9C%8B%E7%BB%93%E6%9E%9C"><span class="toc-number">10.7.</span> <span class="toc-text">使用git branch查看结果</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8git-switch%E5%88%87%E6%8D%A2%E5%88%86%E6%94%AF"><span class="toc-number">10.8.</span> <span class="toc-text">使用git switch切换分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%A7%A3%E5%86%B3%E5%86%B2%E7%AA%81"><span class="toc-number">10.9.</span> <span class="toc-text">解决冲突</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E6%96%B0%E5%88%86%E6%94%AFfeature1"><span class="toc-number">10.9.1.</span> <span class="toc-text">创建新分支feature1</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%96%B0%E5%88%86%E6%94%AF%E4%BF%AE%E6%94%B9-readme-txt"><span class="toc-number">10.9.2.</span> <span class="toc-text">新分支修改 readme.txt</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%96%B0%E5%88%86%E6%94%AF%E4%B8%8A%E6%8F%90%E4%BA%A4"><span class="toc-number">10.9.3.</span> <span class="toc-text">新分支上提交</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%87%E6%8D%A2%E5%88%B0master%E5%88%86%E6%94%AF"><span class="toc-number">10.9.4.</span> <span class="toc-text">切换到master分支</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9master%E5%88%86%E6%94%AF%E4%B8%AD%E7%9A%84readme-txt%E6%96%87%E4%BB%B6"><span class="toc-number">10.9.5.</span> <span class="toc-text">修改master分支中的readme.txt文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9C%A8master%E5%88%86%E6%94%AF%E4%B8%AD%E6%8F%90%E4%BA%A4"><span class="toc-number">10.9.6.</span> <span class="toc-text">在master分支中提交</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%9D%E8%AF%95merge-feature1"><span class="toc-number">10.9.7.</span> <span class="toc-text">尝试merge feature1</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8git-status%E6%9F%A5%E7%9C%8B%E5%86%B2%E7%AA%81%E6%96%87%E4%BB%B6"><span class="toc-number">10.9.8.</span> <span class="toc-text">使用git status查看冲突文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8cat%E6%9F%A5%E7%9C%8B%E5%86%B2%E7%AA%81%E5%86%85%E5%AE%B9"><span class="toc-number">10.9.9.</span> <span class="toc-text">使用cat查看冲突内容</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%89%8B%E5%8A%A8%E4%BF%AE%E6%94%B9%E5%86%B2%E7%AA%81%E5%B9%B6%E6%8F%90%E4%BA%A4"><span class="toc-number">10.9.10.</span> <span class="toc-text">手动修改冲突并提交</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8git-log%E6%9F%A5%E7%9C%8B%E5%88%86%E6%94%AF%E7%9A%84%E5%90%88%E5%B9%B6%E6%83%85%E5%86%B5"><span class="toc-number">10.9.11.</span> <span class="toc-text">使用git log查看分支的合并情况</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9C%80%E5%90%8E%E5%8F%AF%E4%BB%A5%E5%88%A0%E9%99%A4feature1%E5%88%86%E6%94%AF"><span class="toc-number">10.9.12.</span> <span class="toc-text">最后可以删除feature1分支</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%88%86%E6%94%AF%E7%AE%A1%E7%90%86%E7%AD%96%E7%95%A5"><span class="toc-number">11.</span> <span class="toc-text">分支管理策略</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8-no-ff%E7%9A%84%E6%96%B9%E5%BC%8F%E5%90%88%E5%B9%B6"><span class="toc-number">11.1.</span> <span class="toc-text">使用--no-ff的方式合并</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AD%96%E7%95%A5"><span class="toc-number">11.2.</span> <span class="toc-text">策略</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Bug%E5%88%86%E6%94%AF"><span class="toc-number">12.</span> <span class="toc-text">Bug分支</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8git-stash%E4%BF%9D%E5%AD%98%E5%BD%93%E5%89%8D%E5%B7%A5%E4%BD%9C%E7%8E%B0%E5%9C%BA"><span class="toc-number">12.1.</span> <span class="toc-text">使用git stash保存当前工作现场</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%A1%AE%E5%AE%9A%E8%A6%81%E4%BF%AE%E5%A4%8Dbug%E7%9A%84%E5%88%86%E6%94%AF"><span class="toc-number">12.2.</span> <span class="toc-text">确定要修复bug的分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E5%A4%8Dbug%E5%90%8E%E8%BF%9B%E8%A1%8C%E6%8F%90%E4%BA%A4%E5%90%88%E5%B9%B6"><span class="toc-number">12.3.</span> <span class="toc-text">修复bug后进行提交合并</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E5%A4%8D%E5%AE%8C%E6%88%90%EF%BC%8C%E5%88%87%E6%8D%A2%E5%88%B0master%E5%88%86%E6%94%AF%E5%90%88%E5%B9%B6%EF%BC%8C%E7%84%B6%E5%90%8E%E5%88%A0%E9%99%A4issue"><span class="toc-number">12.4.</span> <span class="toc-text">修复完成，切换到master分支合并，然后删除issue</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%81%A2%E5%A4%8D%E5%B7%A5%E4%BD%9C%E7%8E%B0%E5%9C%BA"><span class="toc-number">12.5.</span> <span class="toc-text">恢复工作现场</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B0%86master%E4%BF%AE%E5%A4%8D%E7%9A%84bug%E5%90%88%E5%B9%B6%E5%88%B0dev%E4%B8%8A"><span class="toc-number">12.6.</span> <span class="toc-text">将master修复的bug合并到dev上</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Feature%E5%88%86%E6%94%AF"><span class="toc-number">13.</span> <span class="toc-text">Feature分支</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%96%B0%E5%BB%BA%E5%88%86%E6%94%AF"><span class="toc-number">13.1.</span> <span class="toc-text">新建分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#feature%E5%88%86%E6%94%AF%E4%B8%8Edev%E5%88%86%E6%94%AF%E5%90%88%E5%B9%B6"><span class="toc-number">13.2.</span> <span class="toc-text">feature分支与dev分支合并</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%8B%A5%E6%83%B3%E8%A6%81%E5%88%A0%E9%99%A4%E6%9C%AA%E5%90%88%E5%B9%B6%E7%9A%84%E5%88%86%E6%94%AF"><span class="toc-number">13.2.1.</span> <span class="toc-text">若想要删除未合并的分支</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%A4%9A%E4%BA%BA%E5%8D%8F%E4%BD%9C%E5%BC%80%E5%8F%91"><span class="toc-number">14.</span> <span class="toc-text">多人协作开发</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Rebase%E6%93%8D%E4%BD%9C"><span class="toc-number">15.</span> <span class="toc-text">Rebase操作</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%A0%87%E7%AD%BE%E7%AE%A1%E7%90%86"><span class="toc-number">16.</span> <span class="toc-text">标签管理</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E6%A0%87%E7%AD%BE"><span class="toc-number">16.1.</span> <span class="toc-text">创建标签</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%93%8D%E4%BD%9C%E6%A0%87%E7%AD%BE"><span class="toc-number">16.2.</span> <span class="toc-text">操作标签</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Git%E7%9A%84%E7%BD%91%E7%AB%99"><span class="toc-number">17.</span> <span class="toc-text">Git的网站</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#2020-9-20%E6%9B%B4%E6%96%B0"><span class="toc-number">18.</span> <span class="toc-text">2020.9.20更新</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#git%E5%88%A0%E9%99%A4%E8%BF%9C%E7%A8%8B%E6%96%87%E4%BB%B6%EF%BC%88%E4%BF%9D%E7%95%99%E6%9C%AC%E5%9C%B0%EF%BC%89"><span class="toc-number">18.1.</span> <span class="toc-text">git删除远程文件（保留本地）</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%A2%84%E8%A7%88%EF%BC%88%E4%B8%8D%E5%88%A0%E9%99%A4%EF%BC%89"><span class="toc-number">18.1.1.</span> <span class="toc-text">预览（不删除）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%A1%AE%E5%AE%9A%E6%97%A0%E8%AF%AF%E5%90%8E%E5%88%A0%E9%99%A4%E6%96%87%E4%BB%B6"><span class="toc-number">18.1.2.</span> <span class="toc-text">确定无误后删除文件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8F%90%E4%BA%A4%E5%B9%B6%E6%8E%A8%E9%80%81%E8%87%B3%E8%BF%9C%E7%A8%8B%E6%9C%8D%E5%8A%A1%E5%99%A8"><span class="toc-number">18.1.3.</span> <span class="toc-text">提交并推送至远程服务器</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2021/08/01/%E8%B7%A8%E5%9F%9F/" title="跨域问题"><img data-lazy-src="https://jzhmcoo1-1258918430.cos.ap-shanghai.myqcloud.com/markdown/20210801204426-browser.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="跨域问题"/></a><div class="content"><a class="title" href="/2021/08/01/%E8%B7%A8%E5%9F%9F/" title="跨域问题">跨域问题</a><time datetime="2021-08-01T12:42:27.000Z" title="发表于 2021-08-01 20:42:27">2021-08-01</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/06/26/Css-Core-Concepts/" title="css关键概念"><img data-lazy-src="https://gitee.com/jzhmcoo1/jzhmcoo1picrepo/raw/master/img/css.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="css关键概念"/></a><div class="content"><a class="title" href="/2021/06/26/Css-Core-Concepts/" title="css关键概念">css关键概念</a><time datetime="2021-06-26T02:53:41.000Z" title="发表于 2021-06-26 10:53:41">2021-06-26</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/06/21/Cpp-OJ-Environment/" title="C++OJ环境搭建"><img data-lazy-src="https://jzhmcoo1-1258918430.cos.ap-shanghai.myqcloud.com/markdown/20210621082947.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="C++OJ环境搭建"/></a><div class="content"><a class="title" href="/2021/06/21/Cpp-OJ-Environment/" title="C++OJ环境搭建">C++OJ环境搭建</a><time datetime="2021-06-21T00:28:12.000Z" title="发表于 2021-06-21 08:28:12">2021-06-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/06/20/Browser-Cache/" title="浏览器的强缓存和协商缓存"><img data-lazy-src="https://jzhmcoo1-1258918430.cos.ap-shanghai.myqcloud.com/markdown/20210620222035.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="浏览器的强缓存和协商缓存"/></a><div class="content"><a class="title" href="/2021/06/20/Browser-Cache/" title="浏览器的强缓存和协商缓存">浏览器的强缓存和协商缓存</a><time datetime="2021-06-20T14:18:05.000Z" title="发表于 2021-06-20 22:18:05">2021-06-20</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/06/17/Sorting/" title="排序算法汇总"><img data-lazy-src="https://jzhmcoo1-1258918430.cos.ap-shanghai.myqcloud.com/markdown/20210617235208-sorting.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="排序算法汇总"/></a><div class="content"><a class="title" href="/2021/06/17/Sorting/" title="排序算法汇总">排序算法汇总</a><time datetime="2021-06-17T15:53:46.000Z" title="发表于 2021-06-17 23:53:46">2021-06-17</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2021 By lixing</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text"><a target="_blank" rel="noopener" href="http://www.beian.miit.gov.cn/"><img class="icp-icon" src="/images/icp.png"><span>备案号：沪ICP备20019376号-1</span></a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>if (!window.MathJax) {
  window.MathJax = {
    loader: {
      source: {
        '[tex]/amsCd': '[tex]/amscd'
      }
    },
    tex: {
      inlineMath: [ ['$','$'], ["\\(","\\)"]],
      tags: 'ams'
    },
    options: {
      renderActions: {
        findScript: [10, doc => {
          for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
            const display = !!node.type.match(/; *mode=display/)
            const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display)
            const text = document.createTextNode('')
            node.parentNode.replaceChild(text, node)
            math.start = {node: text, delim: '', n: 0}
            math.end = {node: text, delim: '', n: 0}
            doc.math.push(math)
          }
        }, ''],
        addClass: [200,() => {
          document.querySelectorAll('mjx-container:not([display=\'true\']').forEach( node => {
            const target = node.parentNode
            if (!target.classList.contains('has-jax')) {
              target.classList.add('mathjax-overflow')
            }
          })
        }, '', false]
      }
    }
  }
  
  const script = document.createElement('script')
  script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js'
  script.id = 'MathJax-script'
  script.async = true
  document.head.appendChild(script)
} else {
  MathJax.startup.document.state(0)
  MathJax.texReset()
  MathJax.typeset()
}</script><script>function loadValine () {
  function initValine () {
    let initData = {
      el: '#vcomment',
      appId: 'eLIUaG0QmIrM06RLR7ib4AWK-gzGzoHsz',
      appKey: '4WOHEFT9gxfwKDLWQ3Dlc1xi',
      placeholder: '英雄别着急走,留下姓名~',
      avatar: 'monsterid',
      meta: 'nick,mail,link'.split(','),
      pageSize: '10',
      lang: 'zh-CN',
      recordIP: false,
      serverURLs: '',
      emojiCDN: 'https://i0.hdslb.com/bfs/emote/',
      emojiMaps: {"2020":"dc709fac0d361370bcf0d36d32adb97df7c95824.png@112w_112h.png","热词系列_知识增加":"142409b595982b8210b2958f3d340f3b47942645.png@112w_112h.png","热词系列_梦幻联动":"4809416be5ca787c2ec3e897e4fd022a58da6e0e.png@112w_112h.png","热词系列_希望没事":"6c0d2e6c486d1ba5afd6204a96e102652464a01d.png@112w_112h.png","热词系列_泪目":"bba3703ab90b7d16fe9dbcb85ed949db687f8331.png@112w_112h.png","热词系列_保护":"55f8f6445ca7c3170cdfc5b16036abf639ce9b57.png@112w_112h.png","热词系列_害怕":"d77e2de26da143249f0c0ad7a608c27152c985bf.png@112w_112h.png","热词系列_爱了爱了":"2a165b555ba20391316366c664ed7891883dc5aa.png@112w_112h.png","热词系列_吹爆":"b528220f9c37256ed6a37f05bf118e44b08b81e5.png@112w_112h.png","热词系列_三连":"21f15fe11b7a84d2f2121c16dec50a4e4556f865.png@112w_112h.png","热词系列_可以":"e08543c71202b36c590094417fcfbb80c3506cd8.png@112w_112h.png","热词系列_打卡":"a9cf77c78e1b9b40aa3ed4862402fba008ee2f51.png@112w_112h.png","热词系列_妙啊":"0e98299d7decf5eaffad854977946075c3e91cb8.png@112w_112h.png","热词系列_这次一定":"a01ca28923daa7cc896c42f27deb4914e20dd572.png@112w_112h.png","热词系列_AWSL":"c37f88cf799f9badf9d84b7671dc3dd98c0fc0c2.png@112w_112h.png","热词系列_递话筒":"98e6950e39fbb4dd1c576042063ca632074070ba.png@112w_112h.png","热词系列_你细品":"535e00658e7e47966f154d3a167fa2365ebc4321.png@112w_112h.png","热词系列_咕咕":"d8065c2e7ce48c929317a94553499a46fecc262a.png@112w_112h.png","热词系列_你可真星":"54c8ddff400abfe388060cabfbb579280fdea1be.png@112w_112h.png","热词系列_标准结局":"3de98174b510cf7dc5fd1bd08c5d881065e79137.png@112w_112h.png","热词系列_危":"5cc6c3357c4df544dd8de9d5c5c0cec97c7c9a56.png@112w_112h.png","热词系列_张三":"255a938f39cea625032b6650036b31aa26c50a3c.png@112w_112h.png","热词系列_害":"cbe798a194612958537c5282fcca7c3bcd2aa15c.png@112w_112h.png","热词系列_我裂开了":"29bd57ec4e8952880fea6c9e47aee924e91f10c4.png@112w_112h.png","热词系列_有内味了":"7ca61680a905b5b6e2e335c630e725b648b03b4d.png@112w_112h.png","热词系列_猛男必看":"c97064450528a0e45c7e7c365a15fbb13fd61d8c.png@112w_112h.png","热词系列_奥力给":"c9b8683827ec6c00fea5327c9bec14f581cef2aa.png@112w_112h.png","热词系列_问号":"c1d1e76c12180adc8558f47006fe0e7ded4154bb.png@112w_112h.png","热词系列_我哭了":"9e0b3877d649aaf6538fbdd3f937e240a9d808e4.png@112w_112h.png","热词系列_高产":"9db817cba4a7f4a42398f3b2ec7c0a8e0c247c42.png@112w_112h.png","热词系列_我酸了":"a8cbf3f6b8cd9377eeb15b9172f3cd683b2e4650.png@112w_112h.png","热词系列_真香":"e68497c775feaac1c3b1a6cd63a50cfb11b767c4.png@112w_112h.png","热词系列_我全都要":"d424d1ad8d14c1c9b8367842bc68c658b9229bc1.png@112w_112h.png","热词系列_神仙UP":"a49e0d0db1e7d35a0f7411be13208951ab448f03.png@112w_112h.png","热词系列_你币有了":"84820c2b147a8ca02f3c4006b63f76c6313cbfa0.png@112w_112h.png","热词系列_不愧是你":"9ff2e356797c57ee3b1675ade0883d2d2247be9b.png@112w_112h.png","热词系列_锤":"35668cc12ae25b9545420e4a85bf21a0bfc03e5d.png@112w_112h.png","热词系列_秀":"50782fbf5d9b7f48f9467b5c53932981e321eedc.png@112w_112h.png","热词系列_爷关更":"faad40c56447f1f8abcb4045c17ce159d113d1fd.png@112w_112h.png","热词系列_有生之年":"f41fdafe2d0fbb8e8bc1598d2cf37e355560103a.png@112w_112h.png","热词系列_镇站之宝":"24e7a6a6e6383c987215fb905e3ee070aca259b5.png@112w_112h.png","热词系列_我太南了":"a523f3e4c63e4db1232365765d0ec452f83be97e.png@112w_112h.png","热词系列_完结撒花":"ea9db62ff5bca8e069cd70c4233353a802835422.png@112w_112h.png","热词系列_大师球":"f30089248dd137c568edabcb07cf67e0f6e98cf3.png@112w_112h.png","热词系列_知识盲区":"ccc94600b321a28116081e49ecedaa4ee8728312.png@112w_112h.png","热词系列_“狼火”":"33ccd3617bfa89e9d1498b13b7542b63f163e5de.png@112w_112h.png","口罩":"3ad2f66b151496d2a5fb0a8ea75f32265d778dd3.png@112w_112h.png","微笑":"685612eadc33f6bc233776c6241813385844f182.png@112w_112h.png","笑":"81edf17314cea3b48674312b4364df44d5c01f17.png@112w_112h.png","呲牙":"b5a5898491944a4268360f2e7a84623149672eb6.png@112w_112h.png","OK":"4683fd9ffc925fa6423110979d7dcac5eda297f4.png@112w_112h.png","星星眼":"63c9d1a31c0da745b61cdb35e0ecb28635675db2.png@112w_112h.png","哦呼":"362bded07ea5434886271d23fa25f5d85d8af06c.png@112w_112h.png","嫌弃":"de4c0783aaa60ec03de0a2b90858927bfad7154b.png@112w_112h.png","喜欢":"8a10a4d73a89f665feff3d46ca56e83dc68f9eb8.png@112w_112h.png","酸了":"92b1c8cbceea3ae0e8e32253ea414783e8ba7806.png@112w_112h.png","大哭":"2caafee2e5db4db72104650d87810cc2c123fc86.png@112w_112h.png","害羞":"9d2ec4e1fbd6cb1b4d12d2bbbdd124ccb83ddfda.png@112w_112h.png","无语":"44667b7d9349957e903b1b62cb91fb9b13720f04.png@112w_112h.png","疑惑":"b7840db4b1f9f4726b7cb23c0972720c1698d661.png@112w_112h.png","调皮":"8290b7308325e3179d2154327c85640af1528617.png@112w_112h.png","喜极而泣":"485a7e0c01c2d70707daae53bee4a9e2e31ef1ed.png@112w_112h.png","奸笑":"bb84906573472f0a84cebad1e9000eb6164a6f5a.png@112w_112h.png","偷笑":"6c49d226e76c42cd8002abc47b3112bc5a92f66a.png@112w_112h.png","大笑":"ca94ad1c7e6dac895eb5b33b7836b634c614d1c0.png@112w_112h.png","阴险":"ba8d5f8e7d136d59aab52c40fd3b8a43419eb03c.png@112w_112h.png","捂脸":"6921bb43f0c634870b92f4a8ad41dada94a5296d.png@112w_112h.png","囧":"12e41d357a9807cc80ef1e1ed258127fcc791424.png@112w_112h.png","呆":"33ad6000d9f9f168a0976bc60937786f239e5d8c.png@112w_112h.png","抠鼻":"cb89184c97e3f6d50acfd7961c313ce50360d70f.png@112w_112h.png","惊喜":"0afecaf3a3499479af946f29749e1a6c285b6f65.png@112w_112h.png","惊讶":"f8e9a59cad52ae1a19622805696a35f0a0d853f3.png@112w_112h.png","笑哭":"c3043ba94babf824dea03ce500d0e73763bf4f40.png@112w_112h.png","妙啊":"b4cb77159d58614a9b787b91b1cd22a81f383535.png@112w_112h.png","doge":"bba7c12aa51fed0199c241465560dfc2714c593e.png@112w_112h.png","滑稽":"d15121545a99ac46774f1f4465b895fe2d1411c3.png@112w_112h.png","吃瓜":"4191ce3c44c2b3df8fd97c33f85d3ab15f4f3c84.png@112w_112h.png","打call":"431432c43da3ee5aab5b0e4f8931953e649e9975.png@112w_112h.png","点赞":"1a67265993913f4c35d15a6028a30724e83e7d35.png@112w_112h.png","鼓掌":"895d1fc616b4b6c830cf96012880818c0e1de00d.png@112w_112h.png","尴尬":"cb321684ed5ce6eacdc2699092ab8fe7679e4fda.png@112w_112h.png","冷":"cb0ebbd0668640f07ebfc0e03f7a18a8cd00b4ed.png@112w_112h.png","灵魂出窍":"43d3db7d97343c01b47e22cfabeca84b4251f35a.png@112w_112h.png","委屈":"d2f26cbdd6c96960320af03f5514c5b524990840.png@112w_112h.png","傲娇":"010540d0f61220a0db4922e4a679a1d8eca94f4e.png@112w_112h.png","疼":"905fd9a99ec316e353b9bd4ecd49a5f0a301eabf.png@112w_112h.png","吓":"9c10c5ebc7bef27ec641b8a1877674e0c65fea5d.png@112w_112h.png","生病":"0f25ce04ae1d7baf98650986454c634f6612cb76.png@112w_112h.png","吐":"06946bfe71ac48a6078a0b662181bb5cad09decc.png@112w_112h.png","嘘声":"e64af664d20716e090f10411496998095f62f844.png@112w_112h.png","捂眼":"c5c6d6982e1e53e478daae554b239f2b227b172b.png@112w_112h.png","思考":"cfa9b7e89e4bfe04bbcd34ccb1b0df37f4fa905c.png@112w_112h.png","再见":"fc510306bae26c9aec7e287cdf201ded27b065b9.png@112w_112h.png","翻白眼":"eba54707c7168925b18f6f8b1f48d532fe08c2b1.png@112w_112h.png","哈欠":"888d877729cbec444ddbd1cf4c9af155a7a06086.png@112w_112h.png","奋斗":"bb2060c15dba7d3fd731c35079d1617f1afe3376.png@112w_112h.png","墨镜":"3a03aebfc06339d86a68c2d893303b46f4b85771.png@112w_112h.png","撇嘴":"531863568e5668c5ac181d395508a0eeb1f0cda4.png@112w_112h.png","难过":"a651db36701610aa70a781fa98c07c9789b11543.png@112w_112h.png","抓狂":"4c87afff88c22439c45b79e9d2035d21d5622eba.png@112w_112h.png","生气":"3195714219c4b582a4fb02033dd1519913d0246d.png@112w_112h.png","视频卫星":"dce6fc7d6dfeafff01241924db60f8251cca5307.png@112w_112h.png","11周年":"d3b2d5dc028c75ae4df379f4c3afbe186d0f6f9b.png@112w_112h.png","鸡腿":"c7860392815d345fa69c4f00ef18d67dccfbd574.png@112w_112h.png","干杯":"8da12d5f55a2c7e9778dcc05b40571979fe208e6.png@112w_112h.png","爱心":"ed04066ea7124106d17ffcaf75600700e5442f5c.png@112w_112h.png","锦鲤":"643d6c19c8164ffd89e3e9cdf093cf5d773d979c.png@112w_112h.png","胜利":"b49fa9f4b1e7c3477918153b82c60b114d87347c.png@112w_112h.png","加油":"c7aaeacb21e107292d3bb053e5abde4a4459ed30.png@112w_112h.png","保佑":"fafe8d3de0dc139ebe995491d2dac458a865fb30.png@112w_112h.png","抱拳":"89516218158dbea18ab78e8873060bf95d33bbbe.png@112w_112h.png","响指":"1b5c53cf14336903e1d2ae3527ca380a1256a077.png@112w_112h.png","支持":"3c210366a5585706c09d4c686a9d942b39feeb50.png@112w_112h.png","拥抱":"41780a4254750cdaaccb20735730a36044e98ef3.png@112w_112h.png","怪我咯":"07cc6077f7f7d75b8d2c722dd9d9828a9fb9e46d.png@112w_112h.png","跪了":"f2b3aee7e521de7799d4e3aa379b01be032698ac.png@112w_112h.png","黑洞":"e90ec4c799010f25391179118ccd9f66b3b279ba.png@112w_112h.png","老鼠":"8e6fb491eb1bb0d5862e7ec8ccf9a3da12b6c155.png@112w_112h.png","福到了":"5de5373d354c373cf1617b6b836f3a8d53c5a655.png@112w_112h.png","加油武汉":"eb966aaa5b690d3f9308a9f936f5b5a72a7f956b.png@112w_112h.png"},
      enableQQ: false,
      path: window.location.pathname,
    }

    if (true) { 
      initData.requiredFields= ('nick,mail'.split(','))
    }
    
    if (false) {
      const otherData = false
      initData = Object.assign(initData, otherData)
    }
    
    const valine = new Valine(initData)
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !false) {
  if (false) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="false"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>